using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class controls_usrLoginStatus : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ImgClose1.Attributes.Add("width", "24");
        ImgClose1.Attributes.Add("height", "23");
        ImgClose2.Attributes.Add("width", "24");
        ImgClose2.Attributes.Add("height", "23");

        if (Session[CE.Global.General.UserId] != null && Session[CE.Global.General.UserTypeId] != null)
        {
            divLoginInfo.Visible = false;
            if (Convert.ToInt32(Session[CE.Global.General.UserTypeId]) ==
                Convert.ToInt32(CE.Global.CEUserType.Customer))
            {
                //if (Request.Url.PathAndQuery.Contains("viewresulthistory.aspx"))
                //{
                //    hplSavedQuotes.Enabled = false;
                //}
                //else
                //{
                //    hplSavedQuotes.Enabled = true;
                //}

                //if (Request.Url.PathAndQuery.Contains("editprofile.aspx"))
                //{
                //    hplEditProfile.Enabled = false;
                //}
                //else
                //{
                //    hplEditProfile.Enabled = true;

                //}


                if (Session[CE.Global.General.UserEmail] != null)
                {
                    //lblUserName.Text = Resources.Menu.Hello.ToString()+ " " + Session[CE.Global.General.UserEmail].ToString();
                    //lblUserName.Text = Session[CE.Global.General.UserName].ToString();



                    //liLogOut.Visible = true;
                    //liLogOut.Attributes.Add("class", "signout");
                    btnLogout.Visible = true;

                    //liSavedQuotes.Visible = true;
                    hplSavedQuotes.Visible = true;
                    //liEditProfile.Visible = true;
                    hplEditProfile.Visible = true;
                }
                else
                {
                    //lblUserName.Text = "No Email";

                    //liLogOut.Attributes.Add("class", "signout");
                    //liLogOut.Visible = true;
                    btnLogout.Visible = true;

                    //liSavedQuotes.Visible = true;
                    hplSavedQuotes.Visible = true;
                    //liEditProfile.Visible = true;
                    hplEditProfile.Visible = true;
                }
            }
            else if (Convert.ToInt32(Session[CE.Global.General.UserTypeId]) ==
                Convert.ToInt32(CE.Global.CEUserType.Provider))
            {
                if (Session[CE.Global.General.ProviderCompanyId] != null)
                {
                    //liSavedQuotes.Visible = true;
                    hplSavedQuotes.Visible = true;
                    hplSavedQuotes.NavigateUrl = "~/Provider/ProviderHome.aspx";
                    //liEditProfile.Visible = false;
                    hplEditProfile.Visible = false;
                    //liLogOut.Visible = true;
                    btnLogout.Visible = true;

                    if (Session[CE.Global.General.ProviderCompanyId].ToString() == CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.AZCPProviderCompanyID"))
                    {
                        lblUserName.Text = Resources.Menu.Hello.ToString() + " " + Session[CE.Global.General.UserEmail].ToString();//"UAT - AZCP Insurance";
                        //liSavedQuotes.Visible = true;
                        hplSavedQuotes.Text = "Go AZCP Insurance Home Page";
                        //hplSavedQuotes.NavigateUrl = "~/Provider/ProviderHome.aspx";
                        //liEditProfile.Visible = false;
                        //liLogOut.Visible = true;
                    }
                    else if (Session[CE.Global.General.ProviderCompanyId].ToString() == CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.MSIGProviderCompanyID"))
                    {
                        //lblUserName.Text = Resources.Menu.Hello.ToString() + " " + Session[CE.Global.General.UserEmail].ToString();//"UAT - MSIG Insurance";
                        //liSavedQuotes.Visible = true;
                        hplSavedQuotes.Text = "Go MSIG Insurance Home Page";
                        //hplSavedQuotes.NavigateUrl = "~/Provider/ProviderHome.aspx";
                        //liEditProfile.Visible = false;
                        //liLogOut.Visible = true;
                    }
                    else if (Session[CE.Global.General.ProviderCompanyId].ToString() == CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.AXAProviderCompanyID"))
                    {
                        //lblUserName.Text = Resources.Menu.Hello.ToString() + " " + Session[CE.Global.General.UserEmail].ToString();//"UAT - AXA Insurance";
                        //liSavedQuotes.Visible = true;
                        hplSavedQuotes.Text = "Go AXA Insurance Home Page";
                        //hplSavedQuotes.NavigateUrl = "~/Provider/ProviderHome.aspx";
                        //liEditProfile.Visible = false;
                        //liLogOut.Visible = true;
                    }
                    else if (Session[CE.Global.General.ProviderCompanyId].ToString() == CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.LMGProviderCompanyID"))
                    {
                        //lblUserName.Text = Resources.Menu.Hello.ToString() + " " + Session[CE.Global.General.UserEmail].ToString();//"UAT - LMG Insurance";
                        //liSavedQuotes.Visible = true;
                        hplSavedQuotes.Text = "Go LMG Insurance Home Page";
                        //hplSavedQuotes.NavigateUrl = "~/Provider/ProviderHome.aspx";
                        //liEditProfile.Visible = false;
                        //liLogOut.Visible = true;
                    }
                    else if (Session[CE.Global.General.ProviderCompanyId].ToString() == CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.ChartisProviderCompanyID"))
                    {
                        //lblUserName.Text = Resources.Menu.Hello.ToString() + " " + Session[CE.Global.General.UserEmail].ToString();//"UAT - Chartis Insurance";
                        //liSavedQuotes.Visible = true;
                        hplSavedQuotes.Text = "Go Chartis Insurance Home Page";
                        //hplSavedQuotes.NavigateUrl = "~/Provider/ProviderHome.aspx";
                        //liEditProfile.Visible = false;
                        //liLogOut.Visible = true;
                    }
                    else if (Session[CE.Global.General.ProviderCompanyId].ToString() == CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.BKIProviderCompanyID"))
                    {
                        //lblUserName.Text = Resources.Menu.Hello.ToString() + " " + Session[CE.Global.General.UserEmail].ToString();//"UAT - Bangkok Insurance";
                        //liSavedQuotes.Visible = true;
                        hplSavedQuotes.Text = "Go Bangkok Insurance Home Page";
                        //hplSavedQuotes.NavigateUrl = "~/Provider/ProviderHome.aspx";
                        //liEditProfile.Visible = false;
                        //liLogOut.Visible = true;
                    }
                    else
                    {
                        //lblUserName.Text = "UAT - Provider";
                        //liLogOut.Visible = true;
                    }
                }
                else
                {
                    //lblUserName.Text = "UAT Site - Provider";
                    //liLogOut.Visible = true;
                }
            }
            else
            {
                //lblUserName.Text = "";
                //liLogOut.Attributes.Add("class", "first");
                //liLogOut.Visible = false;
                btnLogout.Visible = false;

                //liSavedQuotes.Visible = false;
                hplSavedQuotes.Visible = false;
                //liEditProfile.Visible = false;
                hplEditProfile.Visible = false;
            }
        }
        else
        {
            divUserInfo.Visible = false;
            divLoginInfo.Visible = true;
            //if (!Page.IsPostBack)
            //{
            //    GetScript();
            //}
        }

        //liLogOut.Visible = false;
    }

    protected void btnLogout_Click(object sender, EventArgs e)
    {
        string _redirectUrl = CE.Global.General.GetUrl("~/user/logout.aspx", Page);
        Response.Redirect(_redirectUrl);
    }

    protected void btnForgotPassword_Click(object sender, EventArgs e)
    {
        string _redirectUrl = CE.Global.General.GetUrl("~/user/passwordrecovery.aspx", Page);
        Response.Redirect(_redirectUrl);
    }

    private void GetScript()
    {

        string _emailaddress = Resources.CarInsurance.EmailAddress;
        string _password = Resources.CarInsurance.Password;

        txtEmail.Text = _emailaddress;
        txtEmail.ToolTip = _emailaddress;
        txtEmail.Attributes.Add("onblur", "javascript:if(this.value == '') { this.value = '" + _emailaddress + "';}");
        txtEmail.Attributes.Add("onfocus", "javascript:if(this.value == '" + _emailaddress + "') { this.value = '';}");

        txtPassword.Text = _password;
        txtPassword.ToolTip = _password;
        txtPassword.Attributes.Add("onblur", "javascript:if(this.value == '') { this.value = '" + _password + "';}");
        txtPassword.Attributes.Add("onfocus", "javascript:if(this.value == '" + _password + "') { this.value = '';}");
        
        //function DefaultFirstName(TextBoxControl, TextBoxEvent) {
        //    if (TextBoxControl.value.length == 0 && TextBoxEvent.type == "blur") {
        //        TextBoxControl.value = "{Given Name}";
        //    }
        //}

        //function DefaultSurName(TextBoxControl, TextBoxEvent) {
        //    if (TextBoxControl.value.length == 0 && TextBoxEvent.type == "blur") {
        //        TextBoxControl.value = "{Surname}";
        //    }
        //}

        //function ClearText(TextBoxControl, TextBoxEvent) {
        //    if (TextBoxControl.value == "{Given Name}") {
        //        TextBoxControl.value = "";
        //    }
        //    if (TextBoxControl.value == "{Surname}") {
        //        TextBoxControl.value = "";
        //    }
        //}
    }
}
